package com.wnxy.common.base;


import com.wnxy.common.base.enums.IBaseCode;
import com.wnxy.common.base.enums.impl.BusinessCode;
import com.wnxy.common.base.enums.impl.ResultCode;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel("统一返回结果")
public class Result<T> {
    @ApiModelProperty("返回状态码")
    private Integer code;
    @ApiModelProperty("返回信息")
    private String message;
    @ApiModelProperty("返回对象")
    private T data;

    public static <T> Result<T> ok(T data) {
        return new Result<>(ResultCode.SUCCESS.getCode(),ResultCode.SUCCESS.getMessage(),data);
    }

    public static <T> Result<T> ok() {
        return new Result<>(ResultCode.SUCCESS.getCode(),ResultCode.SUCCESS.getMessage(),null);
    }

    public static <T> Result<T> fail() {
        return new Result<>(ResultCode.FAIL.getCode(),ResultCode.FAIL.getMessage(),null);
    }

    public static <T> Result<T> fail(String message) {
        return new Result<>(ResultCode.FAIL.getCode(),message,null);
    }

    public static <T> Result<T> fail(T obj) {
        return new Result<>(ResultCode.FAIL.getCode(),ResultCode.FAIL.getMessage(),obj);
    }

    public static <T> Result<T> fail(IBaseCode baseCode) {
        return new Result<>(baseCode.getCode(),baseCode.getMessage(),null);
    }

    public static <T> Result<T> fail(IBaseCode baseCode, T obj) {
        return new Result<>(baseCode.getCode(),baseCode.getMessage(),obj);
    }

    public static void main(String[] args) {
        Result.fail(ResultCode.PARAM_IS_INVALID);
        Result.fail(BusinessCode.ORDER_PAY_FAILD);

    }

}
